import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import '../../resources/kq_theme_colors.dart';

import '../../theme/kq_theme_manager.dart';
import 'entity/kq_form_entity.dart';

/// 通用表单组件 - 表单分类头
///
/// [ItemType.header]
///
/// @author 周卓
///
class KqHeaderItemView extends StatelessWidget {
  /// 通用属性
  final KqFormEntity entity;

  const KqHeaderItemView({Key? key, required this.entity}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var bgColor = entity.backgroundColor ?? KqThemeColors.bgTransparent;
    return Visibility(
      visible: entity.visible,
      child: Container(
        width: double.infinity,
        color: bgColor,
        padding: EdgeInsets.only(
            left: 0,
            right: entity.paddingHorizontal ??
                KqThemeManager.instance
                    .getConfig()
                    .formConfig
                    .paddingHorizontal ??
                24.r,
            top: 8.r,
            bottom: 8.r),
        child: Row(
          children: [
            /// 是否必填
            Container(
              width: entity.paddingHorizontal ??
                  KqThemeManager.instance
                      .getConfig()
                      .formConfig
                      .paddingHorizontal ??
                  24.r,
              padding: EdgeInsets.only(right: 2.r),
              child: Text(
                "∗",
                textAlign: TextAlign.end,
                style: TextStyle(
                    fontSize: KqThemeManager.instance
                            .getConfig()
                            .formConfig
                            .titleFontSize ??
                        24.sp,
                    color: entity.mustInput
                        ? KqThemeColors.textRed
                        : KqThemeColors.bgTransparent),
              ),
            ),

            /// 标题
            Expanded(
              child: Text(
                entity.title,
                textAlign: TextAlign.start,
                style: TextStyle(
                    fontSize: entity.headerFontSize ??
                        (KqThemeManager.instance
                                .getConfig()
                                .formConfig
                                .headerFontSize ??
                            12.sp),
                    color: KqThemeColors.text59),
              ),
            )
          ],
        ),
      ),
    );
  }
}
